package vsa.migrations.junit.envreader;

import java.io.File;
import java.util.Arrays;
import java.util.Collection;
import java.util.logging.Logger;

import org.eclipse.emf.common.util.URI;
import org.emftext.language.java.JavaClasspath;

public class EnvReaderSystemProperty implements EnvReader {
	
	private static Logger LOGGER = Logger.getLogger(EnvReaderSystemProperty.class.getName());
	
	private final File testsrcPath;

	

	public EnvReaderSystemProperty(File testsrcPath) {
		this.testsrcPath = testsrcPath;
		
	}


	@Override
	public void readEnvironment(JavaClasspath javaClasspath, File projectPath) {
		
	 javaClasspath.registerSourceOrClassFileFolder(URI.createFileURI(this.testsrcPath.getAbsolutePath()));
	 
	 Collection<String> classpathentries = Arrays.asList(System.getProperty("java.class.path").split(File.pathSeparator));
	 for (String nextEntry: classpathentries) {
		 
	   URI fileURI = URI.createFileURI(nextEntry);
	   if (fileURI.isFile())
	      javaClasspath.registerClassifierJar(fileURI);
	   else
	     LOGGER.info("Additional classpath " + fileURI.toFileString() + " is not a file");
	    
	 }
		
	}

}
